﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGCourt.Logic.Common;
using LGCourt.Logic.NBL.DBEntities;
using LGCourt.Logic.NBL;
using NBearLite;

namespace LGCourt.Logic.BLL
{
    public class CaseQuery : LGCourtLogic
    {
        /// <summary>
        /// 得到案件信息
        /// </summary>
        /// <param name="ah"></param>
        /// <param name="dsr"></param>
        /// <returns></returns>
        public pLAXX GetLAXX(string ah, string dsr)
        {
            pLAXX result = new pLAXX();
            ExpressionClip[] selectColumns =
            new ExpressionClip[] { 
                LGCourtColumns.pLAXX.AH,
                LGCourtColumns.pLAXX.AJLX,
                LGCourtColumns.pLAXX.LAAY,
                LGCourtColumns.pLAXX.KTRQ,
                LGCourtColumns.pLAXX.KTDD,
                LGCourtColumns.pLAXX.AJJZJD,
            };

            pDSRXX dsrxx = NBLData.Select(LGCourtColumns.pDSRXX)
               .Where(LGCourtColumns.pDSRXX.AH == ah && LGCourtColumns.pDSRXX.MC == dsr)
               .ToSingleObject<pDSRXX>();
            if (dsrxx == null)
                return null;
            result = NBLData.Select(LGCourtColumns.pLAXX, selectColumns)
               .Where(LGCourtColumns.pLAXX.AH == ah)
               .ToSingleObject<pLAXX>();
            if (result != null)
            {
                ExpressionClip[] ktColumns =
                 new ExpressionClip[] { 
                LGCourtColumns.pKTXX.KTDD,
                LGCourtColumns.pKTXX.KSSJ,                
                 };
                pKTXX ktxx = NBLData.Select(LGCourtColumns.pKTXX, ktColumns)
               .Where(LGCourtColumns.pKTXX.AH == ah)
               .OrderBy(LGCourtColumns.pKTXX.KSSJ.Desc)
               .ToSingleObject<pKTXX>();

                if (ktxx != null)
                {
                    result.KTDD = ktxx.KTDD;
                    result.KTRQ = ktxx.KSSJ;
                }
            }

            return result;
        }
    }
}
